﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.SIESystemManager.Calculate
{
    public class C_D47
    {
        public double GetD47(DataRow[] dr1, DataRow[] dr2)
        {
            double TD47 = 0;

            double D47_Drawers_Qty = 0;
            double D47_Sheet_Matal_500 = 0;
            double D47_Sheet_Matal_501_1300 = 0;
            double D47_Sheet_Matal_1301 = 0;
            double D47_Pulling_Door_Fittings = 0;
            double D47_Install_Door_Fittings = 0;
            double D47_Twisting_Diamond_Needle_Rings = 0;
            double D47_Lock_Screws_Qty = 0;
            double D47_Kind_of_Kitting = 0;
            double D47_Special_Fittings_10 = 0;
            double D47_Special_Fittings_30 = 0;
            double D47_Special_Fittings_50 = 0;           
            //附加工时
            double AD47_Drawers_Qty = 0;
            double AD47_Sheet_Matal_500 = 0;
            double AD47_Sheet_Matal_501_1300 = 0;
            double AD47_Sheet_Matal_1301 = 0;
            double AD47_Pulling_Door_Fittings = 0;
            double AD47_Install_Door_Fittings = 0;
            double AD47_Twisting_Diamond_Needle_Rings = 0;
            double AD47_Lock_Screws_Qty = 0;
            double AD47_Kind_of_Kitting = 0;
            double AD47_Special_Fittings_10 = 0;
            double AD47_Special_Fittings_30 = 0;
            double AD47_Special_Fittings_50 = 0; 
            //单位工时
            double WD47_Drawers_Qty = 0;
            double WD47_Sheet_Matal_500 = 0;
            double WD47_Sheet_Matal_501_1300 = 0;
            double WD47_Sheet_Matal_1301 = 0;
            double WD47_Pulling_Door_Fittings = 0;
            double WD47_Install_Door_Fittings = 0;
            double WD47_Twisting_Diamond_Needle_Rings = 0;
            double WD47_Lock_Screws_Qty = 0;
            double WD47_Kind_of_Kitting = 0;
            double WD47_Special_Fittings_10 = 0;
            double WD47_Special_Fittings_30 = 0;
            double WD47_Special_Fittings_50 = 0; 
            //获取数据库每个工序动作的单位工时和附加工时
            foreach (var drHours in dr2)
            {
                switch (drHours["OPERATIONAL_NAME"].ToString())
                {
                    case "装抽屉数量":
                        WD47_Drawers_Qty = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Drawers_Qty = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装板材500":
                        WD47_Sheet_Matal_500 = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Sheet_Matal_500 = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装板材501-1300":
                        WD47_Sheet_Matal_501_1300 = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Sheet_Matal_501_1300 = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装板材1301":
                        WD47_Sheet_Matal_1301 = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Sheet_Matal_1301 = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "拧金刚针圈":
                        WD47_Twisting_Diamond_Needle_Rings = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Twisting_Diamond_Needle_Rings = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装拉门配件":
                        WD47_Pulling_Door_Fittings = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Pulling_Door_Fittings = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装趟门配件":
                        WD47_Install_Door_Fittings = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Install_Door_Fittings = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "锁螺丝数量":
                        WD47_Lock_Screws_Qty = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Lock_Screws_Qty = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "配件种类":
                        WD47_Kind_of_Kitting = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Kind_of_Kitting = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装特别配件10":
                        WD47_Special_Fittings_10 = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Special_Fittings_10 = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装特别配件30":
                        WD47_Special_Fittings_30 = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Special_Fittings_30 = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "装特别配件50":
                        WD47_Special_Fittings_50 = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD47_Special_Fittings_50 = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                }
            }
            //特征值
            foreach (var drData in dr1)
            {
                D47_Drawers_Qty = double.Parse(string.IsNullOrEmpty(drData["D47_Drawers_Qty"].ToString()) ? "0" : drData["D47_Drawers_Qty"].ToString());
                D47_Sheet_Matal_500 = double.Parse(string.IsNullOrEmpty(drData["D47_Sheet_Matal_500"].ToString()) ? "0" : drData["D47_Sheet_Matal_500"].ToString());
                D47_Sheet_Matal_501_1300 = double.Parse(string.IsNullOrEmpty(drData["D47_Sheet_Matal_501_1300"].ToString()) ? "0" : drData["D47_Sheet_Matal_501_1300"].ToString());
                D47_Sheet_Matal_1301 = double.Parse(string.IsNullOrEmpty(drData["D47_Sheet_Matal_1301"].ToString()) ? "0" : drData["D47_Sheet_Matal_1301"].ToString());
                D47_Pulling_Door_Fittings = double.Parse(string.IsNullOrEmpty(drData["D47_Pulling_Door_Fittings"].ToString()) ? "0" : drData["D47_Pulling_Door_Fittings"].ToString());
                D47_Install_Door_Fittings = double.Parse(string.IsNullOrEmpty(drData["D47_Install_Door_Fittings"].ToString()) ? "0" : drData["D47_Install_Door_Fittings"].ToString());
                D47_Twisting_Diamond_Needle_Rings = double.Parse(string.IsNullOrEmpty(drData["D47_Twisting_Diamond_Needle_Rings"].ToString()) ? "0" : drData["D47_Twisting_Diamond_Needle_Rings"].ToString());
                D47_Lock_Screws_Qty = double.Parse(string.IsNullOrEmpty(drData["D47_Lock_Screws_Qty"].ToString()) ? "0" : drData["D47_Lock_Screws_Qty"].ToString());
                D47_Kind_of_Kitting = double.Parse(string.IsNullOrEmpty(drData["D47_Kind_of_Kitting"].ToString()) ? "0" : drData["D47_Kind_of_Kitting"].ToString());
                D47_Special_Fittings_10 = double.Parse(string.IsNullOrEmpty(drData["D47_Special_Fittings_10"].ToString()) ? "0" : drData["D47_Special_Fittings_10"].ToString());
                D47_Special_Fittings_30 = double.Parse(string.IsNullOrEmpty(drData["D47_Special_Fittings_30"].ToString()) ? "0" : drData["D47_Special_Fittings_30"].ToString());
                D47_Special_Fittings_50 = double.Parse(string.IsNullOrEmpty(drData["D47_Special_Fittings_50"].ToString()) ? "0" : drData["D47_Special_Fittings_50"].ToString());
               
            }
            //装抽屉数量
            if (D47_Drawers_Qty != 0)
            {
                TD47 = TD47 + D47_Drawers_Qty * WD47_Drawers_Qty;
            }
            //装板材500
            if (D47_Sheet_Matal_500 != 0)
            {
                TD47 = TD47 + D47_Sheet_Matal_500 * WD47_Sheet_Matal_500;
            }
            //装板材501-1300
            if (D47_Sheet_Matal_501_1300 != 0)
            {
                TD47 = TD47 + D47_Sheet_Matal_501_1300 * WD47_Sheet_Matal_501_1300;
            }
            //装板材1301
            if (D47_Sheet_Matal_1301 != 0)
            {
                TD47 = TD47 + D47_Sheet_Matal_1301 * WD47_Sheet_Matal_1301;
            }
            //装拉门配件
            if (D47_Pulling_Door_Fittings != 0)
            {
                TD47 = TD47 + D47_Pulling_Door_Fittings * WD47_Pulling_Door_Fittings;
            }
            //装趟门配件
            if (D47_Install_Door_Fittings != 0)
            {
                TD47 = TD47 + D47_Install_Door_Fittings * WD47_Install_Door_Fittings;
            }
            //拧金刚针圈
            if (D47_Twisting_Diamond_Needle_Rings != 0)
            {
                TD47 = TD47 + D47_Twisting_Diamond_Needle_Rings * WD47_Twisting_Diamond_Needle_Rings;
            }
            //锁螺丝数量
            if (D47_Lock_Screws_Qty != 0)
            {
                TD47 = TD47 + D47_Lock_Screws_Qty * WD47_Lock_Screws_Qty;
            }
            //配件种类
            if (D47_Kind_of_Kitting != 0)
            {
                TD47 = TD47 + D47_Kind_of_Kitting * WD47_Kind_of_Kitting;
            }
            //装特别配件10
            if (D47_Special_Fittings_10 != 0)
            {
                TD47 = TD47 + D47_Special_Fittings_10 * WD47_Special_Fittings_10;
            }
            //装特别配件30
            if (D47_Special_Fittings_30 != 0)
            {
                TD47 = TD47 + D47_Special_Fittings_30 * WD47_Special_Fittings_30;
            }
            //装特别配件50
            if (D47_Special_Fittings_50 != 0)
            {
                TD47 = TD47 + D47_Special_Fittings_50 * WD47_Special_Fittings_50;
            }
            return TD47;
        }
    }
}
